<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:insert="~{include :: header('图片导入')}" />
    <link rel="stylesheet" href="/static/css/picture-add.css">
</head>
<body class="hold-transition">
<!-- Site wrapper -->
<div class="container-fluid mt-2 mb-2">
    <!-- Main content -->
    <form class="form-horizontal m" id="form-picture-add">
        <div class="card-body">
            <div class="form-group row">
                <label class="col-sm-2 col-form-label is-required text-sm-right">目录</label>
                <div class="col-sm-9">
                    <input id="directory" name="directory" class="form-control" value="E:\wen\01建筑设计\01建筑大师\" placeholder="请输入目录" type="text" required>
                </div>
            </div>
            <div class="form-group row">
                <label class="col-sm-2 col-form-label is-required text-sm-right">分类</label>
                <div class="col-sm-3">
                    <select id="directoryType" class="form-control">
                        <option value="1">目录是分类</option>
                        <option value="2">目录是专集</option>
                    </select>
                </div>
            </div>
            <div class="form-group row">
                <label class="col-sm-2 col-form-label is-required text-sm-right">分类</label>
                <div class="col-sm-3">
                    <input id="categoryId" name="categoryId" type="hidden"/>
                    <input class="form-control" type="text" id="categoryName" placeholder="请选择分类" readonly="readonly">
                </div>
            </div>
            <div class="form-group row">
                <label class="col-sm-2 col-form-label is-required text-sm-right">等级</label>
                <div class="col-sm-2">
                    <select id="levelId" name="levelId" class="form-control m-b" th:with="type=${memberTypes}" required>
                        <option value="0">普通</option>
                        <option th:each="dict : ${type}" th:text="${dict.title}" th:value="${dict.id}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group row">
                <label class="col-sm-2 col-form-label is-required text-sm-right">售价</label>
                <div class="col-sm-2">
                    <input name="price" class="form-control" value="0"  type="text" required>
                </div>
            </div>
            <div class="form-group row">
                <label class="col-sm-2 col-form-label is-required text-sm-right">属性</label>
                <div class="col-sm-2 pt-2">
                    <label for="isElite"><input type="checkbox" value="1" name="isElite" id="isElite"> 推荐</label>
                    &nbsp;&nbsp;&nbsp;
                    <label for="isTop"><input type="checkbox" value="1" name="isTop" id="isTop"> 固顶</label>
                </div>
                <label class="col-sm-2 col-form-label is-required text-sm-right">过滤</label>
                <div class="col-sm-2 pt-2">
                    <label for="filterTitle"><input type="checkbox" value="1" name="filterTitle" id="filterTitle"> 标题</label>
                </div>
            </div>
            <div class="row">
                <label class="col-sm-2"></label>
                <div class="col-sm-10">
                    <input name="channelId" th:value="${channelId}" type="hidden"/>
                    <button type="button" class="btn btn-primary" onclick="submitPicture()"><i class="fa fa-check"></i>保 存</button>&nbsp;
                    <button type="button" class="btn btn-danger" onclick="parent.layer.closeAll()"><i class="fa fa-reply-all"></i>关 闭 </button>
              </div>
            </div>
        </div>
    </form>
</div>
<th:block th:insert="~{include :: footer}" />
<script src="/static/libs/layui-v2.6.8/layui.js"></script>
<script type="text/javascript">
    var channelId = [[${channelId}]];

    $(function () {
        /*分类-新增-选择父部门树*/
        $('#categoryName').click(function () {
            var options = {
                title: null,
                width: '380px',
                url: "/category/select.html?categoryId=" + $("#categoryId").val() + "&channelId=" + channelId,
                callBack: function (index, layero) {
                    var body = layer.getChildFrame('body', index);
                    setCategory(body.find('#categoryId').val(), body.find('#categoryName').val())
                    layer.close(index);
                }
            };
            $.modal.openOptions(options);
        });

        /*
        $('#picture-correct').click(function () {
            var loading = layer.load(1);
            $.ajax({
                url: "/picture/import/correct.json",
                type: "post",
                dataType: "json",
                data: null,
                timeout: 1800000,
                success: function (result) {
                    layer.close(loading);
                    layer.alert(result.msg);
                }
            });
        })*/
    });

    function setCategory(id, name) {
        $("#categoryId").val(id);
        $("#categoryName").val(name);
    }

    function submitPicture() {
        var categoryId = $("#categoryId").val();
        if (categoryId.length < 1 || categoryId === "0") {
            return layer.msg("请先选择所属分类！");
        }
        var url = "/picture/import/category.json";
        if ($("#directoryType").val() === "2") {
            url = "/picture/import/album.json";
        }
        var data = $("#form-picture-add").serializeArray();
        var loading = layer.load(1);
        $.ajax({
            url: url,
            type: "post",
            dataType: "json",
            data: data,
            timeout: 1800000,
            success: function (result) {
                layer.close(loading);
                layer.alert(result.msg);
            }
        });
    }
</script>
</body>
</html>